package com.wangchao.administrator.zenmechi.ui.fragment.caipuitemfragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wangchao.administrator.zenmechi.R;
import com.wangchao.administrator.zenmechi.bean.caipudetailbean.CaipuDetailDataBean;
import com.wangchao.administrator.zenmechi.image.ImageHepler;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/17.
 */
public class MyAdapterForCaipuList extends BaseAdapter {

    private Context context;
    private List<CaipuDetailDataBean> list;

    public MyAdapterForCaipuList(Context context, List<CaipuDetailDataBean> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.caipu_item_list, viewGroup, false);
            holder  = new ViewHolder(view);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }

        ImageHepler.showImage(context,list.get(i).getPic(),holder.imageCaipu);
        holder.tvName.setText(list.get(i).getName());
        holder.tvSelect.setText("已有"+list.get(i).getSelected_count()+"人选择");

        return view;
    }

    static class ViewHolder {
        @BindView(R.id.image_caipu)
        ImageView imageCaipu;
        @BindView(R.id.tv_select)
        TextView tvSelect;
        @BindView(R.id.tv_name)
        TextView tvName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
